//
// Created by Administrator on 2025/3/25.
//

#ifndef MYTEST_04_SIMU_PROCESS_H
#define MYTEST_04_SIMU_PROCESS_H

// Learn with Examples, 2020, MIT license
#include <systemc>
using namespace sc_core;

SC_MODULE(PROCESS) {
    sc_clock clk; // declares a clock
    SC_CTOR(PROCESS) : clk("clk", 1, SC_SEC) { // instantiate a clock with 1sec periodicity
//        SC_METHOD(method); // register a method
        SC_THREAD(thread); // register a thread
        SC_CTHREAD(cthread, clk); // register a clocked thread
    }
    void method(void) { // define the method member function
        // no while loop here
        std::cout << "method triggered @ " << sc_time_stamp() << std::endl;
        next_trigger(sc_time(1, SC_SEC)); // trigger after 1 sec
    }
    void thread() { // define the thread member function
        while (true) { // infinite loop make sure it never exits
            std::cout << "thread triggered @ " << sc_time_stamp() << std::endl;
            wait(1, SC_SEC); // wait 1 sec before execute again
        }
    }
    void cthread() { // define the cthread member function
        while (true) { // infinite loop
            std::cout << "cthread triggered @ " << sc_time_stamp() << std::endl;
            wait(); // wait for next clk event, which comes after 1 sec
        }
    }
};





#endif //MYTEST_04_SIMU_PROCESS_H
